//
//  cityListViewController.m
//  天气预报
//
//  Created by 娟娟 on 15/9/18.
//  Copyright (c) 2015年 wang. All rights reserved.
//

#import "cityListViewController.h"
#import "CityViewController.h"
#import "mainViewController.h"
#import "FMDatabase.h"
@interface cityListViewController ()
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property(nonatomic,strong) UIButton *btn;
@property (weak, nonatomic) IBOutlet UIButton *locateBtn;
@property (weak, nonatomic) IBOutlet UIButton *twoBtn;
@property (weak, nonatomic) IBOutlet UIButton *threeBtn;
@property (weak, nonatomic) IBOutlet UIButton *fourBtn;
@property (weak, nonatomic) IBOutlet UIButton *fiveBtn;
@property (weak, nonatomic) IBOutlet UIButton *sixBtn;
@property (weak, nonatomic) IBOutlet UIButton *sevenBtn;
@property (weak, nonatomic) IBOutlet UIButton *eightBtn;
@property (weak, nonatomic) IBOutlet UIButton *nineBtn;

- (IBAction)rtnBtnClicked;
- (IBAction)twoBtnClicked;

@end

@implementation cityListViewController

-(BOOL)prefersStatusBarHidden
{
    return YES;
}


- (IBAction)threeBtnClicked {
    
    int flag = 1;
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.threeBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.threeBtn.currentTitle;
            flag = 0;

        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.threeBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];
        

    }
  

}
- (IBAction)fourBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.fourBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.fourBtn.currentTitle;
            flag = 0;

        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.fourBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];

    }
   
}
- (IBAction)fiveBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.fiveBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.fiveBtn.currentTitle;
            flag = 0;

        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.fiveBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];

    }
 
}

- (IBAction)sixBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.sixBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.sixBtn.currentTitle;
            flag = 0;

        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.sixBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];

    }
    
}


- (IBAction)sevenBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.sevenBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            flag = 0;
            mainVc.selectedCityName = self.sevenBtn.currentTitle;
        }
    }
    if(flag)
    {
    [appDelegate.citys addObject:self.sevenBtn.currentTitle];
    mainViewController *mainVc = [[mainViewController alloc]init];
    [self.navigationController pushViewController:mainVc animated:NO];
    }
}
- (IBAction)eightBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.eightBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.eightBtn.currentTitle;
            flag = 0;
        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.eightBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];
        
    }
   

}

- (IBAction)nineBtnClicked:(id)sender {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.nineBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            [self.navigationController pushViewController:mainVc animated:NO];
            mainVc.selectedCityName = self.nineBtn.currentTitle;
            flag = 0;
        }
    }
    if (flag) {
        [appDelegate.citys addObject:self.nineBtn.currentTitle];
        mainViewController *mainVc = [[mainViewController alloc]init];
        [self.navigationController pushViewController:mainVc animated:NO];
    }
   

}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.locateBtn.layer.masksToBounds = YES;
    self.locateBtn.layer.cornerRadius = 10;
    self.searchBar.delegate = self;
    
}

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    mainViewController *mainVC = [[mainViewController alloc]init];
    [self.navigationController pushViewController:mainVC animated:YES];
}
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
     if (appDelegate.citys.count<5)
     {
          CityViewController *city = [[CityViewController alloc]init];
         [self.navigationController pushViewController:city animated:YES];
     }
     else
     {
         MBProgressHUD *HUD = [[MBProgressHUD alloc]initWithView:self.view];
         
         [self.view addSubview:HUD];
         HUD.labelText = @"不能多于五个城市啦~~~";
         HUD.mode = MBProgressHUDModeCustomView;
         [HUD showAnimated:YES whileExecutingBlock:^{
             
             sleep(2);
             
         } completionBlock:^{
             [HUD removeFromSuperview];
             
         }];
     }
    return YES;
}

- (IBAction)rtnBtnClicked {
    mainViewController *mainVc = [[mainViewController alloc]init];
    [self.navigationController pushViewController:mainVc animated:YES];
    
}

- (IBAction)twoBtnClicked {
    AppDelegate *appDelegate= [[UIApplication sharedApplication]delegate];
    int flag = 1;
    for(int i = 0;i<appDelegate.citys.count;i++)
    {
        if ([appDelegate.citys[i] isEqualToString: self.twoBtn.currentTitle]) {
            mainViewController *mainVc = [[mainViewController alloc]init];
            mainVc.selectedCityName = self.twoBtn.currentTitle;
            [self.navigationController pushViewController:mainVc animated:NO];
            flag = 0;
        }
    }
    if (flag) {
      [appDelegate.citys addObject:self.twoBtn.currentTitle];
       mainViewController *mainVc = [[mainViewController alloc]init];
       [self.navigationController pushViewController:mainVc animated:NO];
    }
 
  
}
@end
